﻿namespace CraftingCode.SymbolicCalculator
{
    public class LiteralTokenizationRule : TokenizationRule
    {
        public override bool CanCreateNextTokenIn(string expression)
        {
            return char.IsNumber(expression[0]);
        }

        public override Token CreateNextTokenIn(string expression)
        {
            var value = expression.ReadCharactersWhile((c, i) => char.IsNumber(c));
            return new Token()
                {
                    Node = new Literal(int.Parse(value)),
                    Priority = 1,
                    Value = value
                };
        }
    }
}